<template>
  <div class="wrap">
    <header>
      <h3>团购管理</h3>
    </header>
    <main>
      <div class="tuangou1">
        <div class="chose">
          <div class="ipt">
            <label>订单类型:</label>
            <input type="text" placeholder="团购名称" />
            <label>状态:</label>
            <van-dropdown-menu>
              <van-dropdown-item v-model="value6" :options="option6" @change="screening6(value6)" />
            </van-dropdown-menu>
          </div>
          <div class="chose">
            <v-distpicker></v-distpicker>
            <div class="ipt">
              <input type="text" placeholder="关键字" v-model="val" />
              <button @click="handleSearch()">搜索</button>
            </div>
          </div>
        </div>
        <div class="list">
          <el-table :data="tableData" style="width: 100%">
            <el-table-column label="序号" prop="id" width="180"></el-table-column>
            <el-table-column label="图片" prop="bianhao" width="180"></el-table-column>
            <el-table-column label="楼盘名称" prop="title" width="180"></el-table-column>
            <el-table-column label="楼盘地址" prop="city" width="180"></el-table-column>
            <el-table-column label="发起人" prop="name" width="180"></el-table-column>
            <el-table-column label="起始时间" prop="date" width="180"></el-table-column>
            <el-table-column label="状态" prop="staus" width="180"></el-table-column>
            <el-table-column label="操作">
              <template slot-scope="scope">
                <el-button size="mini" type="danger" @click="handleDelete(scope.row.id)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <!-- <el-pagination background layout="prev, pager, next" :total="1000"></el-pagination> -->
        </div>
      </div>
    </main>
  </div>
</template>

<script>
import axios from "axios";
import VDistpicker from "v-distpicker";

export default {
  data() {
    return {
      tableData: [],
      value6: "请选择",
      option6: [
        { text: "请选择", value: "请选择" },
        { text: "开启", value: "开启" },
        { text: "关闭", value: "关闭" }
      ],
      val: ""
    };
  },
  created() {
    this.getList();
  },
  methods: {
    async getList() {
      const res = await axios.post("/api/search", { val: this.val });
      console.log(res);
      this.tableData = res.data.data;
    },
    handleSearch() {
      this.getList();
    },
    handleDelete(id) {
      axios({
        url: "/api/delList",
        method: "post",
        data: { id }
      }).then(res => {
        console.log(res);
        this.getList();
      });
    },

    screening6(value) {
      axios({
        url: "/api/screening6",
        method: "post",
        data: {
          value: value
        }
      }).then(res => {
        if (res.data.code === 1) {
          //调用函数
          this.getlist();
        } else {
          this.list = res.data.data;
        }
      });
    }
  }
};
</script>

<style lang='scss' scoped>
.wrap {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  // border: 1px solid #999;
}
header {
  height: 30px;
  line-height: 30px;
  color: #999;
}
main {
  .tuangou1 {
    .chose {
      display: flex;
      align-items: center;
      margin-top: 10px;
      label {
        font-size: 17px;
        color: #333;
        margin-right: 5px;
      }
      .ipt {
        display: flex;
        align-items: center;
        margin-left: 20px;
        input {
          border-collapse: collapse;
          width: 200px;
          height: 37px;
          border-radius: 3px;
          background: #fff;
          padding-left: 12px;
        }
        button {
          width: 80px;
          height: 37px;
          border: none;
          background: #999;
          font-size: 16px;
          border-radius: 3px;
          margin-left: 8px;
        }
      }
    }
    .list {
      width: 100%;
      height: 100%;
      display: flex;
      flex-direction: column;
      margin-top: 15px;
      tr {
        border: 1px solid #ccc;
        line-height: 20px;
        text-align: center;
        align-items: center;
        th {
          line-height: 40px;
          padding: 0 60px;
        }
        td {
          line-height: 35px;
          padding: 0 5px;
        }
      }
    }
  }
}
</style>